#!/usr/local/bin/python
# -*- coding: utf-8 -*-


'''
类功能：对记账记账凭证的数据合法性进行检查
'''

def CheckVoucherData(   propertyIncreaseName,
                        propertyIncreaseValue,
                        propertyDecreaseName,
                        propertyDecreaseValue,
                        ownershipIncreaseName,
                        ownershipIncreaseValue,
                        ownershipDecreaseName,
                        ownershipDecreaseValue):

        #对数据基本合法性进行检查
        dataCount=0
        if (propertyIncreaseValue != 0):
                dataCount = dataCount+1

        if (propertyDecreaseValue !=0 ):
                dataCount = dataCount + 1

        if (ownershipIncreaseValue != 0):
                dataCount = dataCount + 1

        if (ownershipDecreaseValue != 0):
                dataCount = dataCount + 1

        if dataCount<2:
                return False, "数据空缺"
        #记账模式的合法性进行检查
        #转账模式
        if (propertyIncreaseValue != 0 and
                propertyDecreaseValue != 0):
                if (propertyIncreaseValue != propertyDecreaseValue):
                        return False, "取款模式，非法数据！"

                if (propertyIncreaseName==None or propertyIncreaseName==""):
                        return False, "取款模式，资产增加科目为空！"

                if (propertyDecreaseName == None or propertyDecreaseName == ""):
                        return False, "取款模式，资产减少科目为空！"
        #收入模式
        if (propertyIncreaseValue != 0 and
            ownershipIncreaseValue != 0):
                if (propertyIncreaseValue != ownershipIncreaseValue):
                        return False, "借款模式，非法数据"

                if (propertyIncreaseName ==None or propertyIncreaseName == ""):
                        return False, "借款模式，资产增加科目为空！"

                if (ownershipIncreaseName==None or ownershipIncreaseName == ""):
                        return False, "借款模式，权属增加科目为空！"

        #还款模式
        if (propertyDecreaseValue != 0 and
            ownershipDecreaseValue != 0):
                if (propertyDecreaseValue != ownershipDecreaseValue):
                        return False, "还款模式，非法数据"

                if (propertyDecreaseName==None or propertyDecreaseName==""):
                        return False, "还款模式，资产减少科目为空！"

                if (ownershipDecreaseName==None or ownershipDecreaseName==""):
                        return False, "还款模式，资产减少科目为空！"
        #刷卡消费模式
        if (ownershipIncreaseValue != 0 and
            ownershipDecreaseValue != 0):

                if (ownershipIncreaseValue != ownershipDecreaseValue):
                        return False, "刷卡消费模式，非法数据"

                if (ownershipIncreaseName==None or ownershipIncreaseName == ""):
                        return False, "刷卡消费模式，权属增加科目为空！"

                if (ownershipDecreaseName==None or ownershipDecreaseName==""):
                        return False, "刷卡消费模式，资产减少科目为空！"

        return True, "合法数据"